<%@page contentType="text/html;charset=utf-8"%>
<%@page
	import="java.sql.*,java.io.*,com.oreilly.servlet.multipart.DefaultFileRenamePolicy, com.oreilly.servlet.MultipartRequest"%>

<%!static final String JDBC_DRIVER_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	static final String DB_URL = "jdbc:sqlserver://127.0.0.1;databaseName=student;";
	static final String USER_ID = "sa";
	static final String USER_PASSWORD = "test123";%>



<%
	try {
		String path = "C:/";
		int size = 5 * 1024 * 1024;
		MultipartRequest multi = new MultipartRequest(request, path,
				size, "euc-kr", new DefaultFileRenamePolicy());

		File imgfile = multi.getFile("file_path");

		Class.forName(JDBC_DRIVER_NAME);
		Connection con = DriverManager.getConnection(DB_URL, USER_ID,
				USER_PASSWORD);

		FileInputStream fin = new FileInputStream(imgfile);
		PreparedStatement pre = con
				.prepareStatement("insert into ImageTable(imageData) values(?)");
		pre.setBinaryStream(1, fin, (int) imgfile.length());
		pre.executeUpdate();
		System.out.println("Inserting Successfully!");
		pre.close();

		con.close();
	} catch (Exception ex) {
		out.println("error :" + ex);
	}
%>